<template>
	<view class="columnbox wdh-100 content">
		<template v-if="stationinfo!=''">
			<!-- 自动洗车 -->
			<view v-if="door.doorType==0" class="columnbox one-type" @click="curtype=1,doorId=''"
				:class="{'sel-type':curtype==1}">
				<view class="rowbox wdh-100 spb als top-box">
					<view class="columnbox">
						<image src="/static/img/zdxc.png" mode="widthFix" class="type-img"></image>
						<view class="type-name">自动洗车</view>
					</view>
					<view class="columnbox type-desc als">
						<view><text class="def-col">自动洗车说明：</text><text
								style="color: #000;">{{feeSettingszd.directions}}</text> </view>
						<view style="margin-top: 20rpx;"><text class="def-col">支付费用：</text>
							全自动洗车{{feeSettingszd.basePrice}}元/次或
							消耗洗车券一张 </view>
					</view>
				</view>
				<view class="wdh-100 rowbox price-box">
					费用{{feeSettingszd.baseDuration}}分钟{{feeSettingszd.basePrice}}元，每超1分钟增加费用{{feeSettingszd.overtimeHarges}}元
				</view>
			</view>
			<!-- 自助洗车 -->
			<view v-if="door.doorType==1" class="columnbox one-type" @click="curtype=2,doorId=''"
				:class="{'sel-type':curtype==2}">
				<view class="rowbox wdh-100 spb als top-box">
					<view class="columnbox">
						<image src="/static/img/zzcx.png" mode="widthFix" class="type-img"></image>
						<view class="type-name">自助洗车</view>
					</view>
					<view class="columnbox type-desc als">
						<view><text class="def-col">自动洗车说明：</text><text
								style="color: #000;">{{feeSettingszz.directions}}</text> </view>
						<view style="margin-top: 20rpx;"><text class="def-col">支付费用：</text>
							全自动洗车{{feeSettingszz.basePrice}}元/次或
							消耗洗车券一张 </view>
					</view>
				</view>
				<view class="wdh-100 rowbox price-box">
					费用{{feeSettingszz.baseDuration}}分钟{{feeSettingszz.basePrice}}元，每超1分钟增加费用{{feeSettingszz.overtimeHarges}}元
				</view>
			</view>
			<!-- 人工洗车 -->
			<view v-if="door.doorType==2" class="columnbox one-type" @click="curtype=3,doorId=''"
				:class="{'sel-type':curtype==3}">
				<view class="rowbox wdh-100 spb als top-box">
					<view class="columnbox">
						<image src="/static/img/rgyy.png" mode="widthFix" class="type-img"></image>
						<view class="type-name">人工洗车</view>
					</view>
					<view class="columnbox type-desc als">
						<view><text class="def-col">人工洗车说明：</text> 将车辆驶入指定地点
							内 <text style="color: #000;">后由店内工作人员完成洗车</text> </view>
						<view style="margin-top: 20rpx;"><text class="def-col">支付费用：</text> 全自动洗车30.00元/次或
							消耗洗车券一张 </view>
					</view>
				</view>
				<view class="wdh-100 rowbox price-box">费用40.00元每次</view>
			</view>
		</template>
		<view class="wdh-100" style="height: 200rpx;"></view>
		<view class="rowbox bottom-box">
			<view class="columnbox">
				<view class="wallet-title">余额：<text>¥ {{isLogin?(walletinfo.cash||0):0}}</text> </view>
				<view class="wallet-title" style="margin-top: 5rpx;">
					优惠券：<text>{{isLogin?(walletinfo.couponsNum||0):0}}</text> 张
				</view>
			</view>
			<view class="rowbox">
				<view class="rowbox account-box" @click="toRecharge">
					充值余额
				</view>
				<view @click="confirmOrder" class="rowbox pay-btn confirm-btn">开始洗车</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				doorId: '',
				stationinfo: '',
				walletinfo: '',
				submitflag: false,
				couponsId: '',
				feeSettingszd: '',
				feeSettingszz: '',
				feeSettingsrg: '',
				door: ''
			};
		},
		computed: {
			// 通过计算属性将 state 中的 count 映射到组件
			isLogin() {
				return this.$store.state.isLogin;
			},
			userInfo() {
				return this.$store.state.user;
			},
		},
		onLoad(options) {
			this.doorId = options.doorId
			this.getDoorInfo()
		},
		onShow() {
			this.$nextTick(() => {
				if (this.isLogin) {
					this.getWallet()
				}
			})
		},
		methods: {
			getDoorInfo() {
				this.$req.get(`/xcx/stationDoor/qr/${this.doorId}`).then(res => {
					// 先写死
					// this.$req.get(`/xcx/stationDoor/qr/1850726714035867650`).then(res => {
					// console.log(res)
					
					if (res.data.code == 200) {
						// res.data.data.listUrl = res.data.data.listUrl.indexOf('url') ? JSON.parse(res.data.data
						// 	.listUrl) : []
						
						this.stationinfo = res.data.data
						if(this.stationinfo.reservationOrderCounts > 0){
							// 跳转 y页面核销列表
						}else{
							this.door = this.stationinfo.door
							if (res.data.data.feeSettings.washType == 0) {
								this.feeSettingszd = res.data.data.feeSettings
							}
							if (res.data.data.feeSettings.washType == 1) {
								this.feeSettingszz = res.data.data.feeSettings
							} else {
								this.feeSettingsrg = res.data.data.feeSettings
							}
						}
						
					} else {
						uni.showModal({
							title: '开门失败',
							content: res.data.msg,
							complete() {
								uni.switchTab({
									url: '/pages/index/index'
								})
							}
						})
					}
				})
			},
			getWallet() {
				this.$req.get('/xcx/userWallet').then(res => {
					if (res.data.data) {
						this.walletinfo = res.data.data
					}
				})
			},
			toRecharge() {
				if (!this.isLogin) {
					this.$noLog()
					return false
				}
				uni.navigateTo({
					url: '/pages/coupon/buyCoupon'
				})
			},
			confirmOrder() {
				if (!this.isLogin) {
					this.$noLog()
					return false
				}
				if (!this.submitflag) {
					this.submitflag = true
					uni.showLoading({
						title: '加载中'
					})
					this.$req.get('/xcx/stationDoor/open/', {
						doorId: this.doorId,
						couponsId: this.couponsId
					}).then(res => {
						uni.hideLoading()
						this.submitflag = false
						if (res.data.code == 200) {
							uni.showModal({
								title: '洗车开门成功',
								success: () => {
									uni.redirectTo({
										url: '/pages/order/order'
									})
								}
							})
						} else {
							uni.showModal({
								title: res.data.msg
							})
						}
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		font-family: PingFang SC;
		background: #F7F7F7;
		min-height: 100vh;
		justify-content: flex-start;
	}

	.swiper-box {
		height: 500rpx;
		width: 100%;

		image {
			width: 100%;
			height: 500rpx;
		}
	}

	.info-box {
		border-radius: 20rpx 20rpx 0 0;
		background: #fff;
		padding: 20rpx 20rpx;
		margin-top: -20rpx;
		z-index: 2;
	}

	.store-name {
		font-size: 32rpx;
		color: #4F4F4F;
		font-weight: bold;
	}

	.s-zz,
	.s-jm,
	.s-zd,
	.s-qj {
		background: rgba(119, 40, 245, 0.28);
		color: #7728F5;
		font-size: 24rpx;
		width: 90rpx;
		height: 40rpx;
		border-radius: 10rpx;
		margin-left: 20rpx;
	}

	.s-jm {
		background: #1E72CA;
		color: #fff;
	}

	.s-zd {
		background: rgba(64, 149, 229, 0.25);
		color: #4095E5;
	}

	.s-qj {
		background: rgba(15, 64, 245, 0.25);
		color: #0F40F5;
	}

	.jifen-box {
		font-size: 24rpx;
		color: #fff;
		background: #BD3124;
		height: 40rpx;
		border-radius: 10rpx;
		padding: 0 10rpx;
	}

	.s-address {
		font-size: 24rpx;
		color: #6D6A6B;
	}

	.location-icon {
		width: 40rpx;
		height: 40rpx;
	}

	.store-info {
		padding: 20rpx 0;
		border-top: #EFEFEF solid 1px;
		font-size: 24rpx;
		color: #6D6A6B;
	}

	.store-icon {
		width: 28rpx;
		height: 28rpx;
		margin-right: 10rpx;
	}

	.line-box {
		width: 100%;
		height: 20rpx;
		background: #f7f7f7;
	}

	.type-title {
		width: 100%;
		padding: 20rpx 20rpx;
		color: #001629;
		font-size: 28rpx;
	}

	.one-type {
		border: #fff solid 1px;
		box-shadow: 0px 0px 6px 0px rgba(0, 0, 0, 0.1);
		padding: 32rpx 32rpx;
		width: 710rpx;
		border-radius: 20rpx;
		background: #fff;
		margin-top: 20rpx;

		.type-img {
			width: 100rpx;
			height: 100rpx;
		}

		.type-name {
			font-size: 28rpx;
			font-weight: bold;
			margin-top: 10rpx;
		}

		.type-desc {
			width: calc(100% - 140rpx);
			font-size: 28rpx;
			color: #494a4a;
		}

		.top-box {
			padding-bottom: 20rpx;
			border-bottom: #EFEFEF solid 1px;
		}

		.price-box {
			justify-content: flex-start;
			font-size: 28rpx;
			color: #E99D42;
			margin-top: 20rpx;
		}
	}

	.sel-type {
		border: #17698F solid 1px;
	}

	.room-list {
		display: flex;
		flex-wrap: wrap;
		justify-content: flex-start;
		align-items: flex-end;

		.one-room {
			margin-top: 40rpx;
			padding: 20rpx 20rpx;
			box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.1);
			border-radius: 10rpx;
			font-size: 28rpx;
			position: relative;
			margin-right: 24rpx;
			z-index: 1;

			image {
				margin-right: 10rpx;
				width: 40rpx;
				height: 40rpx;
			}

			.status-box {
				background: #fff;
				padding: 0 20rpx;
				line-height: 40rpx;
				position: absolute;
				font-size: 24rpx;
				box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.1);
				position: absolute;
				top: -20rpx;
				right: -10rpx;
				border-radius: 100rpx;
				z-index: 22;
			}
		}
	}

	.bottom-box {
		position: fixed;
		bottom: 0;
		left: 0;
		background: #fff;
		padding: 20rpx 32rpx;
		padding-bottom: 40rpx;
		z-index: 9;
		border-top: #f2f5f5 solid 1px;
		width: 100%;
		justify-content: space-between;
	}

	.account-box,
	.pay-btn {
		font-size: 28rpx;
		color: #1E72CA;
		border: #1E72CA solid 1px;
		border-radius: 10rpx;
		width: 220rpx;
		height: 90rpx;
	}

	.pay-btn {
		width: 220rpx;
		background: #6C6C6C;
		color: #fff;
		border: none;
	}

	.confirm-btn {
		background: #1E72CA;
		color: #fff;
		margin-left: 20rpx;
	}

	.wallet-title {
		font-size: 28rpx;

		text {
			color: #e20500;
			margin-right: 10rpx;
			font-weight: bold;
		}
	}
</style>